package com.sunday.common.core.remoting.base.auth;

import com.sunday.common.core.gson.GsonUtils;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;

/**
 * 当前用户
 *
 * @author zsy
 * @since 2022/10/13
 */
@Slf4j
@Data
@NoArgsConstructor
@AllArgsConstructor
public class CurrentUser implements Serializable {

    public static final String HTTP_HEADER_AUTH_TOKEN_INFO = "tokenInfo";

    /**
     * 当前ID
     */
    private Long id;

    /**
     * 当前用户名称
     */
    private String username;

    public static CurrentUser of(Long id) {
        return new CurrentUser(id, null);
    }

    public static CurrentUser of(Long id, String name) {
        return new CurrentUser(id, name);
    }

    @Override
    public String toString() {
        return GsonUtils.DEFAULT.toJson(this);
    }

}
